package com.kfh.ybracelet.find;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.kfh.ybracelet.R;
import com.kfh.ybracelet.base.BaseActivity;
import com.kfh.ybracelet.utils.Constant;

/**
 * 捐赠activity
 * Created by Aaron on 16/3/8.
 */
public class DonateActivity extends BaseActivity {

    private WebView wv_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_webview);

        initWidget();

    }

    private void initWidget() {
        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);

        tv_title.setText(getResources().getString(R.string.donate));

        iv_left.setOnClickListener(this);

        wv_view = (WebView) findViewById(R.id.wv_donate);
        MyWebViewClient client = new MyWebViewClient();

        WebSettings settings = wv_view.getSettings();

        settings.setDomStorageEnabled(true);
        settings.setJavaScriptEnabled(true);


        wv_view.setWebViewClient(client);
        wv_view.loadUrl(Constant.DONATE);
        wv_view.setWebChromeClient(new WebChromeClient());
    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {

        if (wv_view.canGoBack()) {
            wv_view.goBack();
        }else {
            super.onBackPressed();
        }
    }
}
